package 并发编程16.消息发送测试2;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;

/**
 * @author idea
 * @data 2019/2/10
 */
public class Demo {

    private static DelayQueue delayQueue  = new DelayQueue();

    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                delayQueue.offer(new MyDelayTask("task",1000));
                delayQueue.offer(new MyDelayTask("task",3900));
                delayQueue.offer(new MyDelayTask("task",4500));
                delayQueue.offer(new MyDelayTask("task",5000));
                delayQueue.offer(new MyDelayTask("task",2500));
            }
        }).start();

        while(true){
            Delayed take=delayQueue.take();
            System.out.println(take.toString());
        }
    }
}
